package com.srzk.youthleagueback.controller;

import com.srzk.youthleagueback.pojo.ThematicEducation;
import com.srzk.youthleagueback.results.Result;
import com.srzk.youthleagueback.service.ThematicEducationService;
import org.apache.ibatis.annotations.Param;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/part4")
public class ThematicEducationController {

    @Autowired
    ThematicEducationService service;

    @GetMapping("/thematicEducationList")
    public Result<Map<String,Object>> getThematicEducationList(@RequestParam("user")String user, @RequestParam("year")String year){
        return service.getThematicEducationList(user,year);
    }

    @GetMapping("/thematicEducation")
    public Result<Map<String,Object>> getThematicEducation(@RequestParam("user")String user, @RequestParam("year")String year,@RequestParam("id")Long id){
        return service.getThematicEducation(user,year,id);
    }


    @PostMapping("/thematicEducation")
    public Result<Map<String,Long>> addThematicEducation(ThematicEducation thematicEducation, MultipartFile[] file){
        return service.addThematicEducation(thematicEducation,file);
    }

    @DeleteMapping("/thematicEducation")
    public Result<String> deleteThematicEducation(@RequestParam("user")String user, @RequestParam("year")String year,@RequestParam("id")Long id){
        return service.deleteThematicEducation(user, year, id);
    }

    @PostMapping("/thematicEducationUpdate")
    public Result<String> updateThematicEducation(ThematicEducation thematicEducation,MultipartFile[] files){
        return service.updateThematicEducation(thematicEducation,files);
    }
}
